<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="Hexo Theme Keep">
    <meta name="description" content="Hexo Theme Keep">
    <meta name="author" content="cm_westwood">
    
    <title>
        
            第4周 |
        
        西木同学的代码训练 2022
    </title>
    
<link rel="stylesheet" href="/code_training_2022/css/style.css">

    <link rel="shortcut icon" href="">
    
<link rel="stylesheet" href="/code_training_2022/css/font-awesome.min.css">

    <script id="hexo-configurations">
    let KEEP = window.KEEP || {};
    KEEP.hexo_config = {"hostname":"cm_westwood.gitee.io","root":"/code_training_2022/","language":"en","path":"search.json"};
    KEEP.theme_config = {"toc":{"enable":true,"number":true,"expand_all":true,"init_open":true},"style":{"primary_color":"#0066CC","avatar":"","favicon":"","article_img_align":"left","left_side_width":"260px","content_max_width":"920px","hover":{"shadow":false,"scale":false},"first_screen":{"enable":true,"background_img":"https://xpoet.cn/images/bg.svg","description":"Keep writing and Keep loving."},"scroll":{"progress_bar":{"enable":true},"percent":{"enable":true}}},"local_search":{"enable":true,"preload":false},"code_copy":{"enable":true,"style":"default"},"pjax":{"enable":false},"lazyload":{"enable":true},"version":"3.4.5"};
    KEEP.language_ago = {"second":"%s seconds ago","minute":"%s minutes ago","hour":"%s hours ago","day":"%s days ago","week":"%s weeks ago","month":"%s months ago","year":"%s years ago"};
  </script>
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
<div class="progress-bar-container">
    
        <span class="scroll-progress-bar"></span>
    

    
</div>


<main class="page-container">

    

    <div class="page-main-content">

        <div class="page-main-content-top">
            <header class="header-wrapper">

    <div class="header-content">
        <div class="left">
            
            <a class="logo-title" href="/">
                西木同学的代码训练 2022
            </a>
        </div>

        <div class="right">
            <div class="pc">
                <ul class="menu-list">
                    
                        <li class="menu-item">
                            <a class=""
                               href="/code_training_2022/"
                            >
                                HOME
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/code_training_2022/archives"
                            >
                                ARCHIVES
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/code_training_2022/tags"
                            >
                                TAGS
                            </a>
                        </li>
                    
                    
                        <li class="menu-item search search-popup-trigger">
                            <i class="fas fa-search"></i>
                        </li>
                    
                </ul>
            </div>
            <div class="mobile">
                
                    <div class="icon-item search search-popup-trigger"><i class="fas fa-search"></i></div>
                
                <div class="icon-item menu-bar">
                    <div class="menu-bar-middle"></div>
                </div>
            </div>
        </div>
    </div>

    <div class="header-drawer">
        <ul class="drawer-menu-list">
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/code_training_2022/">HOME</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/code_training_2022/archives">ARCHIVES</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/code_training_2022/tags">TAGS</a>
                </li>
            
        </ul>
    </div>

    <div class="window-mask"></div>

</header>


        </div>

        <div class="page-main-content-middle">

            <div class="main-content">

                
                    <div class="fade-in-down-animation">
    <div class="article-content-container">

        <div class="article-title">
            <span class="title-hover-animation">第4周</span>
        </div>

        
            <div class="article-header">
                <div class="avatar">
                    <img src="">
                </div>
                <div class="info">
                    <div class="author">
                        <span class="name">cm_westwood</span>
                        
                            <span class="author-label">Lv2</span>
                        
                    </div>
                    <div class="meta-info">
                        <div class="article-meta-info">
    <span class="article-date article-meta-item">
        <i class="fas fa-edit"></i>&nbsp;
        <span class="pc">2022-07-17 13:04:47</span>
        <span class="mobile">2022-07-17 13:04</span>
    </span>
    
    
        <span class="article-tags article-meta-item">
            <i class="fas fa-tags"></i>&nbsp;
            <ul>
                
                    <li>
                        <a href="/code_training_2022/tags/Jupyter-Notebook/">Jupyter Notebook</a>&nbsp;
                    </li>
                
                    <li>
                        | <a href="/code_training_2022/tags/Javascript/">Javascript</a>&nbsp;
                    </li>
                
                    <li>
                        | <a href="/code_training_2022/tags/Requirejs/">Requirejs</a>&nbsp;
                    </li>
                
            </ul>
        </span>
    

    
    
    
    
</div>

                    </div>
                </div>
            </div>
        

        <div class="article-content markdown-body">
            <p>jupyter notebook 里的前后端通信；jupyter notebook 里的 requirejs；富文本编辑器</p>
<span id="more"></span>

<p><a href="/code_training_2022/第4周/配套代码.html" style="text-align: center; display: block;">第4周的配套代码</a></p>
<h1 id="jupyter-notebook-里的前后端通信"><a href="#jupyter-notebook-里的前后端通信" class="headerlink" title="jupyter notebook 里的前后端通信"></a>jupyter notebook 里的前后端通信</h1><p>弄清楚 notebook 里的前后端通信全靠 <a class="link"   target="_blank" rel="noopener" href="https://jupyter-notebook.readthedocs.io/en/stable/comms.html" >https://jupyter-notebook.readthedocs.io/en/stable/comms.html<i class="fas fa-external-link-alt"></i></a> 这一页，当前后端通信成为可能，notebook 里的代码设计框架就可以实现桥接的设计模式 <a class="link"   target="_blank" rel="noopener" href="https://refactoringguru.cn/design-patterns/bridge" >https://refactoringguru.cn/design-patterns/bridge<i class="fas fa-external-link-alt"></i></a> ，将前端交互与后端处理之间相互解耦，留下通信协议作为信息交流的渠道。</p>
<h1 id="jupyter-notebook-里的-requirejs"><a href="#jupyter-notebook-里的-requirejs" class="headerlink" title="jupyter notebook 里的 requirejs"></a>jupyter notebook 里的 requirejs</h1><p>在弄清楚 notebook 里的前后端通信的原理之后，我们就可以很方便的在 notebook 里借助 html 技术带来的进步，实现好看的程序交互界面。在 notebook 里使用前端 javascript 框架只能通过 requirejs 的方式动态引入，结合以下这两篇前置知识，</p>
<blockquote>
<p><a class="link"   target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_39072332/article/details/103293347" >https://blog.csdn.net/weixin_39072332/article/details/103293347<i class="fas fa-external-link-alt"></i></a></p>
<p><a class="link"   target="_blank" rel="noopener" href="https://www.runoob.com/w3cnote/requirejs-tutorial-1.html" >https://www.runoob.com/w3cnote/requirejs-tutorial-1.html<i class="fas fa-external-link-alt"></i></a></p>
</blockquote>
<p>下面就通过 html 富文本编辑器在 notebook 中使用的案例</p>
<h1 id="富文本编辑器"><a href="#富文本编辑器" class="headerlink" title="富文本编辑器"></a>富文本编辑器</h1><p>在网上找了一圈，发现了以下这两个好用的富文本编辑器</p>
<ol>
<li><a class="link"   target="_blank" rel="noopener" href="https://www.wangeditor.com/" >https://www.wangeditor.com/<i class="fas fa-external-link-alt"></i></a> wangEditor </li>
<li><a class="link"   target="_blank" rel="noopener" href="https://ckeditor.com/docs/ckeditor5/latest/index.html" >https://ckeditor.com/docs/ckeditor5/latest/index.html<i class="fas fa-external-link-alt"></i></a> CKEditor</li>
</ol>
<p>其中，wangEditor 不支持 requirejs AMD 规范，翻看其 javascript 源代码可以发现其在代码末尾通过 exports. 引入脚手架，因此在通过 requirejs 引入时需要加垫片 shim，指明 wangEditor 的导出命名。</p>
<p>而 CKEditor 本身就支持 AMD 规范，因此直接导入即可。</p>

        </div>

        

        
            <ul class="post-tags-box">
                
                    <li class="tag-item">
                        <a href="/code_training_2022/tags/Jupyter-Notebook/">#Jupyter Notebook</a>&nbsp;
                    </li>
                
                    <li class="tag-item">
                        <a href="/code_training_2022/tags/Javascript/">#Javascript</a>&nbsp;
                    </li>
                
                    <li class="tag-item">
                        <a href="/code_training_2022/tags/Requirejs/">#Requirejs</a>&nbsp;
                    </li>
                
            </ul>
        

        
            <div class="article-nav">
                
                    <div class="article-prev">
                        <a class="prev"
                           rel="prev"
                           href="/code_training_2022/2022/07/23/%E7%AC%AC5%E5%91%A8/"
                        >
                            <span class="left arrow-icon flex-center">
                              <i class="fas fa-chevron-left"></i>
                            </span>
                            <span class="title flex-center">
                                <span class="post-nav-title-item">第5周</span>
                                <span class="post-nav-item">Prev posts</span>
                            </span>
                        </a>
                    </div>
                
                
                    <div class="article-next">
                        <a class="next"
                           rel="next"
                           href="/code_training_2022/2022/07/09/%E7%AC%AC3%E5%91%A8/"
                        >
                            <span class="title flex-center">
                                <span class="post-nav-title-item">第3周</span>
                                <span class="post-nav-item">Next posts</span>
                            </span>
                            <span class="right arrow-icon flex-center">
                              <i class="fas fa-chevron-right"></i>
                            </span>
                        </a>
                    </div>
                
            </div>
        

        
    </div>
</div>


                
            </div>

        </div>

        <div class="page-main-content-bottom">
            <footer class="footer">
    <div class="info-container">
        <div class="copyright-info info-item">
            &copy;
            
              <span>2022</span>
              -
            
            2023&nbsp;<i class="fas fa-heart icon-animate"></i>&nbsp;<a href="/">cm_westwood</a>
        </div>
        
        <div class="theme-info info-item">
            Powered by <a target="_blank" href="https://hexo.io">Hexo</a>&nbsp;|&nbsp;Theme&nbsp;<a class="theme-version" target="_blank" href="https://github.com/XPoet/hexo-theme-keep">Keep v3.4.5</a>
        </div>
        
        
    </div>
</footer>

        </div>
    </div>

    
        <div class="post-tools">
            <div class="post-tools-container">
    <ul class="tools-list">
        <!-- TOC aside toggle -->
        
            <li class="tools-item page-aside-toggle">
                <i class="fas fa-outdent"></i>
            </li>
        

        <!-- go comment -->
        
    </ul>
</div>

        </div>
    

    <div class="right-bottom-side-tools">
        <div class="side-tools-container">
    <ul class="side-tools-list">
        <li class="tools-item tool-font-adjust-plus flex-center">
            <i class="fas fa-search-plus"></i>
        </li>

        <li class="tools-item tool-font-adjust-minus flex-center">
            <i class="fas fa-search-minus"></i>
        </li>

        <li class="tools-item tool-expand-width flex-center">
            <i class="fas fa-arrows-alt-h"></i>
        </li>

        <li class="tools-item tool-dark-light-toggle flex-center">
            <i class="fas fa-moon"></i>
        </li>

        <!-- rss -->
        

        

        <li class="tools-item tool-scroll-to-bottom flex-center">
            <i class="fas fa-arrow-down"></i>
        </li>
    </ul>

    <ul class="exposed-tools-list">
        <li class="tools-item tool-toggle-show flex-center">
            <i class="fas fa-cog fa-spin"></i>
        </li>
        
            <li class="tools-item tool-scroll-to-top flex-center">
                <i class="arrow-up fas fa-arrow-up"></i>
                <span class="percent"></span>
            </li>
        
    </ul>
</div>

    </div>

    
        <aside class="page-aside">
            <div class="post-toc-wrap">
    <div class="post-toc">
        <ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#jupyter-notebook-%E9%87%8C%E7%9A%84%E5%89%8D%E5%90%8E%E7%AB%AF%E9%80%9A%E4%BF%A1"><span class="nav-number">1.</span> <span class="nav-text">jupyter notebook 里的前后端通信</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#jupyter-notebook-%E9%87%8C%E7%9A%84-requirejs"><span class="nav-number">2.</span> <span class="nav-text">jupyter notebook 里的 requirejs</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%AF%8C%E6%96%87%E6%9C%AC%E7%BC%96%E8%BE%91%E5%99%A8"><span class="nav-number">3.</span> <span class="nav-text">富文本编辑器</span></a></li></ol>
    </div>
</div>
        </aside>
    

    <div class="image-viewer-container">
    <img src="">
</div>


    
        <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
          <span class="search-input-field-pre">
            <i class="fas fa-keyboard"></i>
          </span>
            <div class="search-input-container">
                <input autocomplete="off"
                       autocorrect="off"
                       autocapitalize="off"
                       placeholder="Search..."
                       spellcheck="false"
                       type="search"
                       class="search-input"
                >
            </div>
            <span class="popup-btn-close">
                <i class="fas fa-times"></i>
            </span>
        </div>
        <div id="search-result">
            <div id="no-result">
                <i class="fas fa-spinner fa-pulse fa-5x fa-fw"></i>
            </div>
        </div>
    </div>
</div>

    

</main>




<script src="/code_training_2022/js/utils.js"></script>

<script src="/code_training_2022/js/main.js"></script>

<script src="/code_training_2022/js/header-shrink.js"></script>

<script src="/code_training_2022/js/back2top.js"></script>

<script src="/code_training_2022/js/dark-light-toggle.js"></script>



    
<script src="/code_training_2022/js/local-search.js"></script>




    
<script src="/code_training_2022/js/code-copy.js"></script>




    
<script src="/code_training_2022/js/lazyload.js"></script>



<div class="post-scripts">
    
        
<script src="/code_training_2022/js/left-side-toggle.js"></script>

<script src="/code_training_2022/js/libs/anime.min.js"></script>

<script src="/code_training_2022/js/toc.js"></script>

    
</div>



</body>
</html>
